package
{
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.NativeWindow;
	import flash.display.Screen;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageDisplayState;
	import flash.display.StageScaleMode;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.ui.Keyboard;
	
	import flashx.textLayout.formats.BackgroundColor;
	
	import mx.controls.Image;
	
	[SWF(width='800', height='600', backgroundColor='#000000', frameRate='30')]
	
	public class TestFB extends Sprite
	{
		[Embed(source="Y:/Mes documents/Mes Images/wallpaper/album_pic68.jpg")]
			private var Royo:Class;
		
		private var image:Bitmap;
		
		public function TestFB()
		{
			
			//stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
/*			stage.nativeWindow.activate();
*/
				
			//var l:Loader = new Loader();
			//l.load(new URLRequest());
			trace();			
			image = Bitmap(new Royo()); 
			stage.addChild(image);
			
			resizeImage();

			
			stage.addEventListener(KeyboardEvent.KEY_DOWN,exitFB);
			stage.addEventListener(MouseEvent.CLICK,toggleFullscreen);
		}
		
		private function exitFB(e:KeyboardEvent): void
		{
			if (e.keyCode == Keyboard.ESCAPE)
				stage.nativeWindow.close();
		}
		
		private function resizeImage(): void
		{
			var height:Number = stage.stageHeight;
			var width:Number = stage.stageWidth;
			var scale:Number = height/image.bitmapData.height;
			image.scaleX = scale;
			image.scaleY = scale;
			image.x = (width-image.width)/2;
			image.y = (height-image.height)/2;
		}
		
		private function toggleFullscreen(e:MouseEvent): void
		{
			switch (stage.displayState)
			{
				case StageDisplayState.NORMAL:
					stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE; 
					break;
				
				case StageDisplayState.FULL_SCREEN_INTERACTIVE:
					stage.displayState = StageDisplayState.NORMAL;
					break;
			}
			
			resizeImage();
		}
	}
}